define(
	[
		'require'
	],
	function(require){
		var Controller = Ember.Controller.extend({
			keyUpEnent: function(){
				var ctrl = this;
				setTimeout(function(){
					$("#mouseKeyUp").on("keyup",function(event){
						if(event.keyCode == 13){
							ctrl.requireAlerts();
						};
					});
				},0)
			},
			initTime: function(){
		        var ctrl = this;

		        var sdate = new Date(new Date() - timeD_value - 60000-60000);
		        sdate.setSeconds(0);
		        sdate.setMilliseconds(0); 

		        ctrl.set("startDate",new Date(+sdate));

		        var edate = new Date(new Date() - timeD_value-60000);
		        edate.setSeconds(0);
		        edate.setMilliseconds(0); 
		        console.log(new Date(+edate));

		        ctrl.set("endDate",new Date(+edate));
		    },
			alarmColumns: [
				{
					headerText: "级别",
					dataKey:"alertSevertiyName",
					width: 60,
					allowSort: false,
					ensurePxWidth: true,
					cellFormatter: function (args, colume) {
						if (args.row.type & $.wijmo.wijgrid.rowType.data) {
							var ctrl = this.get("controller");
							var date = args.row.data.alertSevertiyName;
							if("严重"==date){
								var cb = $("<div class='label label-important'></div>").text(date);
								cb.appendTo(args.$container);
							}
							if("警告"==date){
								var cb = $("<div class='label label-warning'></div>").text(date);
								cb.appendTo(args.$container);
							}
							if("提醒"==date){
								var cb = $("<div class='label label-info'></div>").text(date);
								cb.appendTo(args.$container);
							}
							return true;
						}
					}
				},
				{
					headerText: "告警类型",
					dataKey:"alertTypeName",
					width: 100,
					allowSort: false,
					ensurePxWidth: true
				},
				{
					headerText: "开始时间",
					dataKey:"firstTime",
					width: 120,
					allowSort: false,
					ensurePxWidth: true,
					cellFormatter: function (args, colume) {
						if (args.row.type & $.wijmo.wijgrid.rowType.data) {
							var ctrl = this.get("controller");
							var date = new Date(args.row.data.firstTime);
							var  dateFor=APM.util.formatDate(date, "yyyy-MM-dd H:mm");
							var cb = $("<div></div>").text(dateFor);
							cb.appendTo(args.$container);
							return true;
						}
					}
				},
				{
					headerText: "最后一次告警时间",
					dataKey:"lastTime",
					width: 150,
					allowSort: false,
					ensurePxWidth: true,
					cellFormatter: function (args, colume) {
						if (args.row.type & $.wijmo.wijgrid.rowType.data) {
							var ctrl = this.get("controller");
							var date = new Date(args.row.data.lastTime);
							var  dateFor=APM.util.formatDate(date, "yyyy-MM-dd H:mm");
							var cb = $("<div></div>").text(dateFor);
							cb.appendTo(args.$container);
							return true;
						}
					}
				},
				{
					headerText: "描述",
					dataKey:"desc",
					allowSort: false,
					cellFormatter: function (args, colume) {
						if (args.row.type & $.wijmo.wijgrid.rowType.data) {
							var data = args.row.data;
							var value = data.desc;

							var $item = $('<div class="column-summary"></div>').appendTo(args.$container);
							$item.html(APM.util.escape(value));

							args.$container.attr("title",value);
							return true;
						}
					}
				}
			],

			alerts: Ember.A(),

			requireAlerts: function() {
				var ctrl = this,
					nodeId = this.get("model.id");

				var startDate = this.get("startDate"),
					endDate = this.get("endDate");

				var params = {
					appId:"default",
					id: nodeId,
					type:'service',
					rows: 10,
					keyWord: this.get("keyWord"),
					startDate: +startDate,
					endDate: +endDate
				};
				//开发调试模式参数
				if( isLocalDebugModel ){
					params = undefined;
				}

				return this.store.ajax("GET", "alarms/latest", params)
				.then(function(response){
					var alerts = response.alerts;
					
					if (alerts.length == 0) {
						ctrl.set("pageIndex",0);
						ctrl.set("pageSize",10);
						ctrl.set("totalRows",0);
					}else{
						ctrl.set("pageIndex",null);
						ctrl.set("pageSize",null);
						ctrl.set("totalRows",null);
					}
					
					ctrl.set("alerts", alerts);
					return response;
				});
			},
			actions: {
				search: function() {
					this.set("pageIndex", 0);
					this.requireAlerts();
					this.get("clickTimePoint");
				},

				timeRangesChange: function(timeRange){
					this.set("startDate", timeRange.startDate);
					this.set("endDate", timeRange.endDate);
					this.set("pageIndex", 0);
					this.requireAlerts();
				}
			}
		});

		APM.ServiceServerNodeserverAlarmsController = Controller;

		return Controller;
	}
);	